/**
 * 
 */
  $(document).ready(function() {
	  var options = { 
			    	 url:"/salonmorandsmigi/CourseServlet?action=advanced", 
			    	 beforeSubmit: validator,
			    	 success:function(data,status,xhr) { 
		    		 			$(".results").html(xhr.responseText);
		    		 			$(".loader").hide();
		    	 				},
				     statusCode: {
				    	 			400: function() {
					    	 			$(".submit").append("<div class=\"fail\">FAIL! bad session input! try again!<\div>");
					    	 			setTimeout("$(\".fail\").remove();",2000);
				    	 			},
			    	 				402: function() {
			    	 					$(".submit").append("<div class=\"fail\">FAIL! course collides with other courses!<\div>");
					    	 			setTimeout("$(\".fail\").remove();",2000);
			    	 				},
			    	 				405: function() {
			    	 					$(".submit").append("<div class=\"fail\">FAIL! course name already exists!<\div>");
					    	 			setTimeout("$(\".fail\").remove();",2000);
			    	 				},
			    	 				500: function() {
			    	 					$(".submit").append("<div class=\"fail\">FAIL! server error!<\div>");
					    	 			setTimeout("$(\".fail\").remove();",2000);
			    	 				}
	  							 }
			    	}; 
	  
	  $("#search").validate({
			rules: {
				groupnum: {
					number: true,
					min: 0
				},
	  			name: {
	  				minlength: 4
	  			}
			},
			messages: {
				groupnum: {
					number: "<br/>Group number must be a number",
					min: "<br/>Group number cannot be a negative number"
				},
				name:{
					minlength: "must be at least 4 characters"
				}
			},
			submitHandler: function(form) {
				$(".loader").show();
			   	$(form).ajaxSubmit(options);
			   }
		});
	  
	  function validator() {
		  return $("#search").validate().form;
	  }
	  
	  
  });
    
